package com.googlecode.gamedroid.gamepad;

import com.googlecode.gamedroid.R;
import com.googlecode.gamedroid.event.EventKey;
import com.googlecode.gamedroid.event.source.ButtonDispatcher;
import com.googlecode.gamedroid.event.source.DPad;
import com.googlecode.gamedroid.event.source.GameButton;
import com.googlecode.gamedroid.event.source.OrientationSensor;

public class GamePadStandard extends GamePad
{
	public static int getDescription()
	{
		return R.string.gamepad_standard_text;
	}
	
	public static int getIcon()
	{
		return R.drawable.gamepad_standard;
	}
	
	public static int getLabel()
	{
		return R.string.gamepad_standard_label;
	}
	
	private ButtonDispatcher buttonDispatcher;
	private OrientationSensor orientation;
	
	@Override
	protected void onStart()
	{
		super.onStart();
		orientation.onStart();
	}
	
	@Override
	protected void onStop()
	{
		super.onStop();
		orientation.onStop();
	}
	
	@Override
	protected void setUpSources()
	{
		short[] eventDPad0 = { EventKey.BTN_0, EventKey.BTN_1, EventKey.BTN_2, EventKey.BTN_3 };
		short[] eventButtonA = { EventKey.BTN_A };
		short[] eventButtonB = { EventKey.BTN_B };
		short[] eventButtonX = { EventKey.BTN_X };
		short[] eventButtonY = { EventKey.BTN_Y };
		short[] eventButtonStart = { EventKey.BTN_START };
		short[] eventButtonSelect = { EventKey.BTN_SELECT };
		short[] eventButtonMode = { EventKey.BTN_MODE };
		
		orientation = new OrientationSensor(this);
		addSource(orientation);
		
		DPad dpad0 = (DPad) findViewById(R.id.dpad0);
		dpad0.setEvents(eventDPad0);
		addSource(dpad0);
		
		GameButton buttonA = (GameButton) findViewById(R.id.button_a);
		buttonA.setEvents(eventButtonA);
		buttonDispatcher.add(buttonA);
		addSource(buttonA);
		
		GameButton buttonB = (GameButton) findViewById(R.id.button_b);
		buttonB.setEvents(eventButtonB);
		buttonDispatcher.add(buttonB);
		addSource(buttonB);
		
		GameButton buttonX = (GameButton) findViewById(R.id.button_x);
		buttonX.setEvents(eventButtonX);
		buttonDispatcher.add(buttonX);
		addSource(buttonX);
		
		GameButton buttonY = (GameButton) findViewById(R.id.button_y);
		buttonY.setEvents(eventButtonY);
		buttonDispatcher.add(buttonY);
		addSource(buttonY);
		
		GameButton buttonStart = (GameButton) findViewById(R.id.button_start);
		buttonStart.setEvents(eventButtonStart);
		buttonDispatcher.add(buttonStart);
		addSource(buttonStart);
		
		GameButton buttonSelect = (GameButton) findViewById(R.id.button_select);
		buttonSelect.setEvents(eventButtonSelect);
		buttonDispatcher.add(buttonSelect);
		addSource(buttonSelect);
		
		GameButton buttonMode = (GameButton) findViewById(R.id.button_mode);
		buttonMode.setEvents(eventButtonMode);
		buttonDispatcher.add(buttonMode);
		addSource(buttonMode);
	}
	
	@Override
	protected void setUpViews()
	{
		setContentView(R.layout.gamepad_standard);
		buttonDispatcher = (ButtonDispatcher) findViewById(R.id.button_dispatcher);
	}
}
